target = ARGUMENTS.get('target', 0)
if target == 'gcw0':
    include_path = ' -I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include'
    bin_path = '/opt/gcw0-toolchain/usr/bin/mipsel-linux-'
    sdl_path = '/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/bin/'
    print "Building Gambatte SDL with GCW Zero toolchain..."
elif target == 'od':
    include_path = ' -Iopt/opendingux-toolchain/usr/include'
    bin_path = '/opt/opendingux-toolchain/usr/bin/mipsel-linux-'
    sdl_path = '/opt/opendingux-toolchain/usr/bin/'
    print "Building Gambatte SDL with OpenDingux toolchain..."
else:
    include_path = ''
    bin_path = ''
    sdl_path = ''

global_cflags = ARGUMENTS.get('CFLAGS', '-Wall -Wextra -O2 -fomit-frame-pointer -ffunction-sections -ffast-math -fsingle-precision-constant -G0' + include_path)
global_cxxflags = ARGUMENTS.get('CXXFLAGS', global_cflags + ' -fno-exceptions -fno-rtti')
global_linkflags = ARGUMENTS.get('LINKFLAGS', '-Wl,--gc-sections')
global_defines = ' -DHAVE_STDINT_H'

vars = Variables()
vars.Add('CC')
vars.Add('CXX')

env = Environment(CPPPATH = ['src', '../libgambatte/include', '../common'],
                  CFLAGS = global_cflags + global_defines,
                  CXXFLAGS = global_cxxflags + global_defines,
                  CC = bin_path + 'gcc',
                  CXX = bin_path + 'g++',
                  LINKFLAGS = global_linkflags + ' -lSDL_image',
                  variables = vars)

env.ParseConfig(sdl_path + 'sdl-config --cflags --libs')

sourceFiles = Split('''
			src/gambatte_sdl.cpp
			src/audiodata.cpp
			src/blitterwrapper.cpp
			src/parser.cpp
			src/sdlblitter.cpp
			src/str_to_sdlkey.cpp
			src/syncfunc.cpp
			SFont.c
			menu.cpp
			libmenu.c
			scaler.c
			../common/adaptivesleep.cpp
			../common/resample/src/chainresampler.cpp
			../common/resample/src/i0.cpp
			../common/resample/src/makesinckernel.cpp
			../common/resample/src/resamplerinfo.cpp
			../common/resample/src/u48div.cpp
			../common/rateest.cpp
			../common/skipsched.cpp
			../common/videolink/rgb32conv.cpp
			../common/videolink/vfilterinfo.cpp
			../common/videolink/vfilters/catrom2x.cpp
			../common/videolink/vfilters/catrom3x.cpp
			../common/videolink/vfilters/kreed2xsai.cpp
			../common/videolink/vfilters/maxsthq2x.cpp
			../common/videolink/vfilters/maxsthq3x.cpp
			../libgambatte/libgambatte.a
		   ''')

conf = env.Configure()
conf.CheckLib('z')
conf.Finish()

env.Program('gambatte_sdl', sourceFiles)
